package edu.towson.greenteam;

import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;

public final class Logger extends Observable
{
 
	// Singleton object
	private static final Logger mLoggerInstance = new Logger();
 	private ArrayList<Observer> observers;
 
	// prevent construction from outside this class 
	private Logger() {
		observers = new ArrayList<Observer>();
	}
 
	public static Logger GetInstance() { 
		return mLoggerInstance; 
	}

/************************************************************************
 
* Methods for being OBSERVABLE
 
***********************************************************************/
 
	@Override
	public void addObserver(Observer o) {
		this.observers.add(o);
	}
 
	@Override
	public void notifyObservers() {
	 
	}
 
	@Override
	public void notifyObservers(Object arg) {
	 
		for (int i=0; i<observers.size(); i++) {
			Observer o = (Observer) observers.get(i);
			o.update(this, arg);
		} 
	} 

	public void LogMessage(String sMessage) {
		// Output to console
		System.out.println(sMessage);
		notifyObservers(sMessage);
	}
}

